﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using JDEduTrain.Framework.Business;
using JDEduTrain.Framework.ViewEntity;
using JDEduTrain.Framework.Entity;
using Wicresoft.Framework.Organization;
using NameControlLib;
using System.Data.SqlClient;

public partial class Page_DeptTrainDetailStat : BaseAuthenticationPage
{

    public string SearchDefaultText
    {
        get
        {
            return "搜索 单位名称";
        }
    }

    public string SearchClause
    {
        get
        {
            if (ViewState["SearchClause"] == null)
                ViewState["SearchClause"] = "1=1";
            return ViewState["SearchClause"].ToString();
        }
        set
        {
            ViewState["SearchClause"] = value;
        }
    }
    protected DataTable DTUserPageList
    {
        get
        {
            if (ViewState["DTUserPageList"] != null)
            {
                return (DataTable)ViewState["DTUserPageList"];
            }
            return new DataTable();
        }
        set
        {
            ViewState["DTUserPageList"] = value;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        this.tbSearch.Attributes.Add("onfocus", string.Format("clearText(this, '{0}');", SearchDefaultText));
        this.tbSearch.Attributes.Add("onblur", string.Format("insertText(this, '{0}');", SearchDefaultText));
        this.tbSearch.Attributes.Add("onkeydown", "searchClick();");
        this.ShowLRLayoutButton = false;
        this.ShowUDLayoutButton = false;
        this.ShowSimpleLayoutButton = false;
        this.ShowAdvancedSearch = false;

        this.Title = "单位学习情况汇总";
        if (!IsPostBack)
        {
            tbSearch.Text = SearchDefaultText;
            this.Order.OrderColumn = "ThirdLevelDeptDisplayName";
            this.Order.OrderDirection = "DESC";
            BindData();
        }

    }

    protected override void Pager_PageChanged(object sender, EventArgs e)
    {
        BindData();
        base.Pager_PageChanged(sender, e);
    }

    protected override void Order_OrderChanged(object sender, EventArgs e)
    {
        BindData();
        base.Order_OrderChanged(sender, e);
    }

    private void BindData()
    {
        float finishScore = 0;
        float.TryParse(ConfigurationManager.AppSettings["TurnsTotalScore"], out finishScore);
        DataTable dtMember = DataAccess.ExecuteProcedure("JDEduTrain.ConnectionString", "uproc_GetDeptTrainDetail", new SqlParameter[] { new SqlParameter("@FinishScore", finishScore) }).Tables[0];
        DataView dv = dtMember.DefaultView;
        dv.RowFilter = SearchClause;
        DTUserPageList = dtMember.Copy();
        DTUserPageList = dv.ToTable();
        Pager.RecordCount = DTUserPageList.Rows.Count;
        DTUserPageList = WebCommon.GetPagedTable(DTUserPageList, Pager.PageIndex + 1, Pager.PageSize);
        rptUserInfo.DataSource = DTUserPageList;
        rptUserInfo.DataBind();

    }

    protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindData();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (tbSearch.Text != string.Empty && tbSearch.Text != SearchDefaultText)
            SearchClause = string.Format("[ThirdLevelDeptDisplayName] LIKE N'%{0}%'", tbSearch.Text);
        else
            SearchClause = "1=1";
        BindData();
    }
    protected void btnAdvancedSearch_Click(object sender, EventArgs e)
    {
        BindData();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindData();
    }
}
